package com.baomihua.demo.controller

import com.baomihua.demo.entiy.User
import com.baomidou.mybatisplus.mapper.Condition
import com.baomidou.mybatisplus.mapper.EntityWrapper
import com.baomidou.mybatisplus.mapper.Wrapper
import com.baomidou.mybatisplus.plugins.Page
import com.baomihua.demo.service.UserService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

/**
 *
 * @author nieqiurong 2017/12/7.
 */
@RestController
@RequestMapping(value = "user")
class UserController {

    @Autowired
    private lateinit var userService: UserService

    //http://127.0.0.1:8080/user/list
    @GetMapping(value = "list")
    fun list():List<User> = userService.selectList(Condition.EMPTY as Wrapper<User>)

    //http://127.0.0.1:8080/user/1
    @GetMapping(value = "{id}")
    fun user(@PathVariable(value = "id") id:Long): User = userService.selectById(id)

    //http://127.0.0.1:8080/user/page?current=1
    @GetMapping(value = "page")
    fun page(page:Page<User>):List<User> = userService.selectPage(page).records

    //http://127.0.0.1:8080/user/1
    @DeleteMapping(value = "{id}")
    fun delete(user: User):Boolean = userService.delete(EntityWrapper<User>(user))
}